Release 10.1A: OpenEdge Application Server:
Developing WebSpeed Applications
Complex HTML mapping that includes a SmartDataObject
Figure 2–7 shows the Web page generated by another sample WebSpeed application,
w-custdir.w.Figure 2–7: Web page generated from w-custdir.w
![]()
The Web page shown in Figure 2–7 interacts with the Customer table of the Sports2000 database like the other examples in this section. However, it also has the ability to add or change records in the table. Moreover, it uses a SmartDataObject to define its query logic. The following sections describe these features in more detail.
Creating a SmartDataObject
SmartDataObjects provide query logic that is separate from the rest of your application. As separate modules, they can be used by multiple applications, can be refined at run time, and can be modified more easily than queries that are embedded within applications. Another advantage to SmartDataObjects is that they can be used on an AppServer™ for multi-tier deployment. See OpenEdge Application Server: Developing AppServer Applications for more information.
SmartDataObjects can easily be created in the AppBuilder. The SmartDataObject associated with
w-custdir.wis calleddcustomer.w.
![]()
To create SmartDataObjects in the AppBuilder:
- Choose File
New from the AppBuilder main menu.
The New dialog box appears:
![]()
- Select SmartDataObject from the list of SmartObjects.
Note that AppBuilder must be connected to a database in order to create a SmartDataObject. The procedures for starting and connecting to a database are described in OpenEdge Getting Started: WebSpeed Essentials .
- Choose Next on the SmartDataObject Wizard, then choose Define Query from page 2 of the wizard.
- In the Query Builder:
- Go to the next dialog box in the wizard (page 4) and choose Add Fields.
- Choose Add and add all of the available fields to the Selected Fields list.
- Go to the final page of the wizard and choose Finish.
You will see a window labeled Untitled, which represents the SmartDataObject you just created. You can save it as
dcustomer.wfrom the File menu of the AppBuilder.When you save a SmartDataObject, you create a number of files: .w, .r, _cl.w, _cl.r, and .i. For more information about the function of these files, or for more information about SmartDataObjects in general, see OpenEdge Development: ADM and SmartObjects and OpenEdge Development: ADM Reference .
For more information about creating SmartDataObjects with the AppBuilder, see the OpenEdge Development: AppBuilder .
Mapping with a SmartDataObject
You can specify
dcustomer.was the data source when you use the HTML Mapping Wizard to map an HTML file likew-custdir.htm:
You can use the HTML Mapping Wizard’s Automap feature to map the fields referenced in
w-custdir.htmto the database fields referenced indcustomer.w. Note that all the fields will map except the hidden fields and theSearchNamefield (shown in bold). These fields are used to pass information to the WebSpeed agent and do not reference fields in the database.The hidden field,
cusrowid, holds a value that identifies the current record that is displayed on the Web page. It establishes a context for the WebSpeed agent when the next request is submitted. The other hidden field,AddMode, holds a value that tells the WebSpeed agent if a new record is to be added or not added when the next request is submitted. The code that utilizes these hidden fields is explained in the following section.Adding code
After the HTML Mapping Wizard completes, you will see a tree view of an untitled Web object, which is similar to Figure 2–8.
Figure 2–8: Tree view of an untitled HTML-mapping object
![]()
From the Code Sections branch of the tree view, you can add all the code that is necessary to complete
w-custdir.w. With Code Sections selected, choose the Edit Code button from the AppBuilder Tool Bar to start the Section Editor. The Section Editor allows you to add new procedures, to modify default procedures, and to invoke and override super procedures. For more information, see the OpenEdge Development: AppBuilder .
![]()
To complete the Web object:
- Create a trigger that responds to the value of cusrowid.
In the trigger, the value of
cusrowidis passed to thesetCurrentRowidsprocedure. Recall that the value ofcusrowidis stored in a hidden field and is set in a prior WebSpeed transaction. The trigger essentially tells the WebSpeed agent which row in the table to refer to. In other words, the trigger establishes a context for the WebSpeed agent by passing information about a previous transaction.In the example Web object, the trigger is called
Web.inputand the code looks similar to the following:
- Create a procedure that responds to the
AddModeflag.In the example Web object, the procedure is called
inputFields, and the code looks similar to the following:
As noted in the comment, this procedure is actually an override to the
inputFieldssuper procedure. This override supplements the standard behavior ofinputFieldsby allowing it to react to the value of theAddModeflag in the hidden field. This code allows the Web object to add a new record to the database.- Create a procedure that manages the unmapped fields.
In the example Web object, the procedure is called
outputFields, and the code looks similar to the following:
As noted in the comment, this procedure is actually an override to the
outputFieldssuper procedure. Its purpose is to identify the correct row for the next transaction. This override sets the value ofab_unmap.custrowidto the rowid of the current record. The value ofab_unmap.custrowidis set before runningoutputFields.The
Note: The AppBuilder online help contains reference pages that describe the syntax and behaviorab_unmaptemporary table holds the values of the fields that are unmapped. In this example, the unmapped fields arecusrowid,SearchName, andAddMode.inputFields,outputFields, and all other super procedures that apply to WebSpeed. For more information about using super procedures, see the OpenEdge Development: ADM and SmartObjects and the OpenEdge Development: ADM Reference .- Modify
process-web-requestso that the Web object responds to button events.The button events are handled in a case statement, as shown in the following segment:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |